﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.UC.生产计划.生产计划.service;
using DevExpress.XtraGrid.Demos.util;
using DevExpress.XtraEditors.Popup;
using DevExpress.XtraGrid.Editors;
using DevExpress.Utils.Win;
using DevExpress.XtraLayout;
using DXApplicationTangche.UC.生产计划.生产批生产.service;

namespace DXApplicationTangche.UC.生产计划.生产计划
{
    public partial class Form未排产客户 : DevExpress.XtraEditors.XtraForm
    {
        private List<DTO未排产客户> DTO未排产客户s = new List<DTO未排产客户>();
        private String shopId { get; set; }
        private String shopName { get; set; }
        public Form未排产客户()
        {
            InitializeComponent();
            this.searchLookUpEdit选择店铺.Properties.DataSource = 生产批生产Service.get店铺一览();
        }

        #region 选择店铺
        private void searchLookUpEdit选择店铺_Popup(object sender, EventArgs e)
        {
            PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
            SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
            LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
            //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
            if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
            {
                //得到空的空间
                EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

                //得到取消按钮，重写点击事件
                Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
                LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
                clearBtn.Click += clearBtn_Click;

                //添加一个simplebutton控件(确认按钮)
                LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
                myLCI.TextVisible = false;
            }
        }
        private void searchLookUpEdit选择店铺View_Click(object sender, EventArgs e)
        {
            int[] a = this.searchLookUpEdit选择店铺.Properties.View.GetSelectedRows();
            if (a.Length > 0)
            {
                foreach (int rowHandle in a)
                {
                    this.shopId = this.searchLookUpEdit选择店铺.Properties.View.GetRowCellValue(rowHandle, "id").ToString();
                    this.shopName = this.searchLookUpEdit选择店铺.Properties.View.GetRowCellValue(rowHandle, "name").ToString();
                }
            }
            //根据店铺查询客户
            try
            {
                this.DTO未排产客户s = 生产计划Service.get未排产客户一览(this.shopId);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            this.gridControl未排产客户.DataSource = this.DTO未排产客户s;
            this.gridView未排产客户.RefreshData();
        }

        /// <summary>
        /// 清除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clearBtn_Click(object sender, EventArgs e)
        {
            this.searchLookUpEdit选择店铺.ToolTip = null;
            searchLookUpEdit选择店铺.EditValue = null;
        }
        private void searchLookUpEdit选择店铺_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            if (null != e.Value)
                e.DisplayText = this.shopName;
        }
        #endregion

        private void gridView未排产客户_DoubleClick(object sender, EventArgs e)
        {
            //new Form未排产订单(
            //    FunctionHelper.GetgridViewValue(this.gridView未排产客户, this.gridView未排产客户.FocusedRowHandle, "customerId")
            //    ).ShowDialog();
        }
    }
}